<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  // 闭包应用-计算打车价格
  // 打车起步价13(3公里内),  之后每多一公里增加 5块钱.  用户输入公里数就可以计算打车价格
  // 如果有拥堵情况,总价格多收取10块钱拥堵费

  var car = (function () {
    var start = 13;
    var total = 0;
    return {
      price: function (n) {
        if(n <= 3){
          total = start;
        } else {
          total = start + (n - 3) * 5;
        }
        return total;
      },
      yd: function(flag){
        flag? total += 10: total += 0;
        return total;
      }
    }

  })()

  console.log(car.price(5));
  console.log(car.yd(true));

  console.log(car.price(2));
</script>
</body>
</html>